using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

namespace CommonTagTime
{
    public class clsSession
    {
        public clsSession() { }//end constructor


        //-----------------------------------------------------------
        /// <summary>
        /// This function use to remove a session
        /// </summary>
        
        public static void Remove(enmSession enm)
        {
            HttpContext.Current.Session.Remove(Convert.ToString(enm));
        }

        public static int GetLanguage()
        {
            int lang = 0;
            try
            {
                if (HttpContext.Current.Session["Language"] == "en-US")
                    lang = 1;
            }
            catch
            {
               
            }
          
            return lang;
        }

        public static bool CheckExist(enmSession enm)
        {
            if (HttpContext.Current.Session[Convert.ToString(enm)] != null)
                return true;
            else
                return false;
        }

        //-----------------------------------------------------------
        /// <summary>
        /// This function return a field name with session as DataRow
        /// </summary>
        public static string Get(enmSession enm, string FieldName)
        {
            string str = string.Empty;
            if (CheckExist(enm))
            {
                DataRow dr;
                try
                {
                    dr = (DataRow)HttpContext.Current.Session[enm.ToString()];
                    str = dr[FieldName].ToString();
                }
                catch (Exception ex)
                {
                    clsFile.WriteLog("clsSession", "Get", ex.ToString());
                }
                finally
                {
                    dr = null;
                }
            }
            return str;
        }

        //-----------------------------------------------------------
        /// <summary>
        /// This function use to check user login or not
        /// </summary>
        public static void CheckLogin()
        {
            if (!CheckExist(enmSession.User))
            {
                HttpContext.Current.Response.Redirect("/?page=login");
            }
        }

        public static void CheckAdminLogin()
        {
            if (!CheckExist(enmSession.Admin))
            {
                HttpContext.Current.Response.Redirect("/admin/login.aspx");
            }
        }

        /// <summary>
        /// Set DataRow into Session
        /// </summary>
        public static void Set(enmSession enm, DataRow dr)
        {
            HttpContext.Current.Session[Convert.ToString(enm)] = dr;
        }

    }//end class
}